*------------------------------------------------------------------------------*
			*** FIGURE S2. CHANGES IN INCUMBENT VOTE SHARE ***
*------------------------------------------------------------------------------*

use "${rawdata}effectsize/wahlges.dta", clear

*------------------------------------------------------------------------------*

***Prepare data
keep if bula==""
keep if wahlj>=1980
keep w* zweit_gue zweit_spd zweit_cdu zweit_fdp zweit_csu zweit_gruen zweit_linke zweit_pds zweit_afd


foreach var of varlist zweit* {	
	if inlist(`var',zweit_gue)==0 replace `var' = 100 * (`var' / zweit_gue)
}

replace zweit_linke = zweit_linke + zweit_pds

replace zweit_cdu = zweit_cdu + zweit_csu

drop zweit_pds zweit_csu

rename zweit_spd 	SPD
rename zweit_cdu 	CDU	
rename zweit_fdp 	FDP
rename zweit_gruen 	GRUNE
rename zweit_linke 	DIELINKE
rename zweit_afd 	AfD


* Oppositions
gen KLEINE 	 = FDP + GRUNE + DIELINKE
gen CDUGRULI = CDU + GRUNE + DIELINKE
gen SWGELBLI = CDU + FDP + DIELINKE
gen R2G 	 = SPD + GRUNE + DIELINKE

* Governments
gen SOZLIB 	= SPD + FDP
gen ROTGRUN = SPD + GRUNE
gen SWGELB 	= CDU + FDP
gen GROKO 	= CDU + SPD




sort wahlj
foreach var in SOZLIB ROTGRUN SWGELB GROKO KLEINE CDUGRULI SWGELBLI R2G {
	gen `var'_change = `var' - `var'[_n-1]
}


gen Incumb_change = .

replace Incumb_change = SOZLIB_change 	if wahlj==1980
replace Incumb_change = SWGELB_change 	if inrange(wahlj,1983,1998) | wahlj==2013
replace Incumb_change = ROTGRUN_change 	if inrange(wahlj,2002,2005)
replace Incumb_change = GROKO_change 	if inrange(wahlj,2017,2021) | wahlj==2009


gen Opp_change = .


replace Opp_change = CDUGRULI_change 	if wahlj==1980
replace Opp_change = R2G_change 		if inrange(wahlj,1983,1998) | wahlj==2013
replace Opp_change = SWGELBLI_change 	if inrange(wahlj,2002,2005)
replace Opp_change = KLEINE_change 		if inrange(wahlj,2017,2021) | wahlj==2009

*------------------------------------------------------------------------------*

***Graph 
tw ///
(bar Incumb_change wahljahr if inlist(wahlj,1998,2005,2009,2013)==1, color(cranberry)) ///
(bar Incumb_change wahljahr if inlist(wahlj,1998,2005,2009,2013)==0, color(navy)) ///
, legend(ring(0) position(8) bmargin(medlarge) rows(2) lab(1 "Change in government after election")  lab(2 "No change in government after election")) ///
title("") ytitle("Percentage point change") graphregion(color(white)) scheme(lean2) xtitle("Election") ///
xlabel(1983 1987 1990 1994 1998 2002 2005 2009 2013 2017) ylabel(, nogrid) yline(0, lc(black))


graph export "${outputs}figure_S2.png", replace width(3000)

*------------------------------------------------------------------------------*

clear

exit
